﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Basmus.Conel
{
    public class CompositeBinder : IBinder
    {
        private readonly IBinder[] _binders;

        public CompositeBinder(params IBinder[] binders)
        {
            _binders = binders;
        }

        public Binding Bind(Type containerType)
        {
            var binding = _binders
                .Select(x => x.Bind(containerType))
                .FirstOrDefault(x => x != null);
            return binding;
        }

        public Binding Bind(Type containerType, Type elementType)
        {
            var binding = _binders
                .Select(x => x.Bind(containerType, elementType))
                .FirstOrDefault(x => x != null);
            return binding;
        }
    }
}
